import 'dart:io';

import 'package:gate_cli/utils/command_util.dart';

extension StringExtension on String {
  String formatClassName({bool checkKey = false}) {
    if (checkKey) {
      final keys = CommandUtil.jsonKeys();
      if (keys.containsKey(this)) {
        final key = keys[this];
        if (key != null && key.isNotEmpty) return key;
      }
    }
    return split('_').map((e) => "${e[0].toUpperCase()}${e.substring(1)}").join();
  }

  String formatFileName() {
    return "${this[0].toLowerCase()}${substring(1)}";
  }

  String formatAssetName() {
    final aName = split('.').first.split('_').map((e) => "${e[0].toUpperCase()}${e.substring(1)}").join();
    return "${aName[0].toLowerCase()}${aName.substring(1)}";
  }

  /// 是否是数字
  bool isDigit() {
    return int.tryParse(this) != null;
  }
}

extension StringExt on String? {
  bool get isNotNullOrEmpty {
    final t = this;
    return t != null && t.isNotEmpty;
  }

  bool get isNullOrEmpty {
    final t = this;
    return t == null || t.isEmpty;
  }
}


extension FileSystemEntityExtension on FileSystemEntity {
  String takeFileNameWithExe() {
    return path.split('/').last;
  }

  String takeFileNameWithoutExe() {
    return path.split('/').last.split('.').first;
  }

  String takeFilePath() {
    return path.split('/').last;
  }
}